package com.example.anql.controller;

import com.example.anql.common.ReturnObject;
import com.example.anql.entity.Shop;
import com.example.anql.service.ShopService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Shop)表控制层
 *
 * @author makejava
 * @since 2022-12-10 12:46:03
 */
@RestController
@RequestMapping("/shop")
public class ShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;

    /**
     * 分页查询
     *
     * @param shop 筛选条件
     * @return 查询结果
     */
    @PostMapping("/queryByPage")
    public ReturnObject queryByPage(@RequestBody  Shop shop ) {

        return  shopService.queryByPage(shop);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("/queryById")
    public ResponseEntity<Shop> queryById(@RequestBody  Shop shop ) {
        return ResponseEntity.ok(this.shopService.queryById(shop.getId()));
    }

    /**
     * 新增数据
     *
     * @param shop 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<Shop> add(@RequestBody Shop shop) {

        return ResponseEntity.ok(this.shopService.insert(shop));
    }

    /**
     * 编辑数据
     *
     * @param shop 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public ResponseEntity<Shop> edit(@RequestBody Shop shop) {
        return ResponseEntity.ok(this.shopService.update(shop));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteById")
    public ResponseEntity<Boolean> deleteById(@RequestBody  Shop shop) {
        return ResponseEntity.ok(this.shopService.deleteById(shop.getId()));
    }

}

